feat: suggest useComposedScrollHandler hook#5854
Closed
ACHP wants to merge 1 commit intosoftware-mansion:mainfrom
Closed
feat: suggest useComposedScrollHandler hook#5854ACHP wants to merge 1 commit intosoftware-mansion:mainfrom
ACHP wants to merge 1 commit intosoftware-mansion:mainfrom
Conversation
The goal of this hook is to be able to compose multiple scrollHandler, and therefore "hide" the fact that a custom scrollView already use a scrollHandler.
Collaborator
|
Hi @ACHP, thanks for your contribution! We were discussing how to implement event handler merging in Reanimated for a while now and soon we will come to some conclusions. We have a couple of approaches here to choose from and we will include your, with adding a new hook, in the process. |
Contributor
github-merge-queue bot
pushed a commit
that referenced
this pull request
May 14, 2024
## Summary There have already been some requests for a way to merge our event handlers. Inspired by #5854, I created a hook that can work with any handlers made using `useEvent`. I will happily accept any comments and suggestions regarding typing since I am not so sure about it. https://github.com/software-mansion/react-native-reanimated/assets/77503811/9c295325-28ce-4ec2-8490-1a7431e8fafd The PR can be merged only ater #5845 (it is also based on it). ## Test plan Open `useComposedEventHandler` example from Example app and watch event callbacks in console.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The goal of this hook is to be able to compose multiple scrollHandler, and therefore "hide" the fact that a custom scrollView already use a scrollHandler.
why
Let's say I want to create a Fancy ScrollView that use
useAnimatedScrollHandlerinternally to do some animation, on the background color for example.I want to expose this new component to the team and let them use their own animations (in addition to mines) using
reanimatedprimitives.Maybe I missed something in the documentation, but as of today it seems that there is no easy way to do it.
We have to provide a custom API for our
FancyScrollViewto handleonScroll,onMomentumScrollEndetc ...This is not ideal because now the implementation details of our FancyScrollView have somehow leaked outside our component.
Existing discussion
#3611
Status
This is still a work in progress, I would really appreciate some feedback on this: